package inputs;

import processing.core.PApplet;
import processingHandling.PAppletWrapper;

/**
 * 
 * Class for handling a pixel location as an Input value.
 * Binds to a PAppletWrapper to sample pixel data from.
 * Contains methods to get the Red, Green, and Blue inputs bound to this object.
 * 
 * @author Dylan James
 *
 */
public class PixelInput extends Input{

	private int x, y; // Pixel coordinates
	private PApplet pApplet; // pApplet to sample from
	private int colorVal; // The current colorVal returned from pApplet
	
	// Variables to store the color specific inputs for this PixelInput
	private PixelInputRed pIRed;
	private PixelInputGreen pIGreen;
	private PixelInputBlue pIBlue;
	
	/**
	 * Constructs a PixelInput from the given values.
	 * 
	 * @param pApplet The pApplet to sample data from
	 * @param x The x coordinate of the pixel
	 * @param y The y coordinate of the pixel
	 */
	public PixelInput(PApplet pApplet, int x, int y){
		this.x = x;
		this.y = y;
		this.pApplet = pApplet;
		colorVal = 0;
		
		pIRed = new PixelInputRed(pApplet, this);
		pIGreen = new PixelInputGreen(pApplet, this);
		pIBlue = new PixelInputBlue(pApplet, this);
	}
	
	@Override
	protected void Update() {
		colorVal = pApplet.get(x, y);
		
		pIRed.Update();
		pIGreen.Update();
		pIBlue.Update();
	}

	@Override
	public int getValue() {
		return colorVal;
	}
	
	/**
	 * @return The x coordinate of this pixel
	 */
	public int getXCoord()
	{
		return this.x;
	}
	
	/**
	 * @return The y coordinate of this pixel
	 */
	public int getYCoord()
	{
		return this.y;
	}
	
	/**
	 * @return The PixelInputRed bound to this PixelInput
	 */
	public PixelInputRed getRedInput(){
		return pIRed;
	}
	
	/**
	 * @return The PixelInputGreen bound to this PixelInput
	 */
	public PixelInputGreen getGreenInput(){
		return pIGreen;
	}
	
	/**
	 * @return The PixelInputBlue bound to this PixelInput
	 */
	public PixelInputBlue getBlueInput(){
		return pIBlue;
	}

}
